﻿using BySoft.Server.Business.UserCode;
using BySoft.Server.Common;
using BySoft.Web.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BySoft.Web.Site.ComPage
{
    public partial class QuerySScheduleDetailIDByHalfTransfer : BasePage
    {
        int m_count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hdBillDate.Value = UIHelper.GetQueryStringValue("billdate");
                BindData(0);
            }
        }

        private void BindData(int pageIndex)
        {
            string strWorkOrderNo = this.txtWorkOrderNo.Text.Trim();
            string strScheduleID = this.txtScheduleID.Text.Trim();
            string strProductID = this.txtProductID.Text.Trim();
            string strProductName = this.txtProductName.Text.Trim();
            string BillDate = this.hdBillDate.Value.Trim();
            DataTable dt = BsHalfTransferBusiness.SelectDialogScheduleDetailList(BillDate,strWorkOrderNo, strScheduleID, strProductID, strProductName, pageIndex, pcData.PageSize, out m_count);
            pcData.RecordCount = m_count;
            dt.Columns.Add("IsCheckName");
            dt.Columns.Add("IsOutSourceName");
            if (dt.Rows.Count != 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    dr["IsCheckName"] = CommonMethod.GetString(dr["IsCheck"]) == "1" ? "是" : "否";
                    dr["IsOutSourceName"] = CommonMethod.GetString(dr["IsOutSource"]) == "1" ? "是" : "否";
                }
                grdResult.DataSource = dt;
                grdResult.DataBind();
                pcData.CurrentIndex = pageIndex;
            }
            else
            {
                UIHelper.BindEmptyGridView(grdResult, dt);
            }
            UIHelper.RunScript(this.Page, "iframeAutoFit();");
        }

        protected void pcData_PageIndexClick(object sender, Controls.PageIndexClickEventArgs e)
        {
            BindData(e.PageIndex);
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            string sReturn = "";
            foreach (GridViewRow gvr in grdResult.Rows)
            {
                Label lblScheduleDetailID = gvr.FindControl("lblScheduleDetailID") as Label;
                Label lblScheduleID = gvr.FindControl("lblScheduleID") as Label;
                Label lblWorkOrderNo = gvr.FindControl("lblWorkOrderNo") as Label;
                Label lblProductID = gvr.FindControl("lblProductID") as Label;
                Label lblProductName = gvr.FindControl("lblProductName") as Label;
                Label lblUnit = gvr.FindControl("lblUnit") as Label;
                Label lblProcessName = gvr.FindControl("lblProcessName") as Label;
                Label lblScheduleProcessID = gvr.FindControl("lblScheduleProcessID") as Label;
                Label lblScheduleNum = gvr.FindControl("lblScheduleNum") as Label;

                if (gvr.RowType == DataControlRowType.DataRow)
                {
                    if (((RadioButton)gvr.FindControl("rbSelect")).Checked)
                    {
                        sReturn = HttpUtility.UrlEncode(lblScheduleDetailID.Text.Trim() + "," +
                            lblScheduleID.Text.Trim() + "," +
                            lblWorkOrderNo.Text.Trim() + "," +
                            lblProductID.Text.Trim() + "," +
                            lblProductName.Text.Trim() + "," +
                            lblUnit.Text.Trim() + "," +
                            lblProcessName.Text.Trim() + "," +
                            lblScheduleProcessID.Text.Trim() + "," +
                            lblScheduleNum.Text.Trim(), Encoding.UTF8);
                        break;
                    }
                }
            }

            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>setCookie(dialogReturn_key,'" + sReturn + "');CloseTopDialog();</script>");
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {

            BindData(0);
        }

        protected void grdResult_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                RadioButton rb = (RadioButton)e.Row.FindControl("rbSelect");
                rb.Attributes.Add("onclick", "judge(this)");
            }
        }
    }
}